<!--
* @author dumeng
视频列表
-->
<template>
  <div class="courseware-container">
    <el-collapse-transition>
      <div v-show="searchshow" class="courseware-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model="listQuery.subjectName"
          placeholder="请输入视频名称搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <div class="courseware-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="courseware-search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="courseware-search separate">
        <div class="courseware-search-inner">
          <el-row>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">视频名称</div>
                <el-input
                  v-model.trim="search.subjectName"
                  style="width: 80%;"
                  class="filter-item"
                  placeholder="请输入视频名称搜索"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">视频分类</div>
                <el-cascader
                  ref="classify"
                  v-model="search.subjectClassify"
                  style="width:80%"
                  clearable
                  :props="classifyProps"
                  :options="classifyOptions"
                />
              </div>
            </el-col>
            <!-- <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">视频类型</div>
                <el-radio-group v-model="search.subjectType" style="width: 80%;margin-top: 20px;">
                  <el-radio label="">全部</el-radio>
                  <el-radio label="KCLX01">视频</el-radio>
                  <el-radio label="KCLX03">音频</el-radio>
                  <el-radio label="KCLX02">pdf文档</el-radio>
                </el-radio-group>
              </div>
            </el-col> -->
          </el-row>
          <el-row>
            <!-- <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">关键词</div>
                <el-input
                  v-model.trim="search.subjectKeyword"
                  style="width: 80%;"
                  class="filter-item"
                  placeholder="请输入关键词搜索"
                />
              </div>
            </el-col> -->
          </el-row>
        </div>
        <div class="courseware-search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="courseware-search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <div v-if="!isSelect" class="courseware-btn">
      <div class="btn-title">
        <span>视频管理</span>
      </div>
      <div class="btn-btns">
        <el-button
          style="margin-left: 10px"
          @click="classificationDialog = true"
        >批量设置</el-button>
        <el-button style="margin-left: 10px;" @click=";(coursewareInfo = {}), (isCreate = true)">新建视频</el-button>
        <el-button style="margin-left: 10px" @click="handleSelectPlatform">选取SaaS平台视频</el-button>
        <el-button v-if="activeTab === '2'" style="margin-left: 10px;" @click="handleSelectDelet">批量删除</el-button>
        <el-button v-if="activeTab === '2'" style="margin-left: 10px;" @click="handleSelectSend">批量发布</el-button>
        <el-button style="margin-left: 10px;" @click="handleUpload">课通云资源导入</el-button>
      </div>
    </div>
    <div v-if="!isSelect" class="classify-tab">
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in statusOptions" :key="item.id" :label="item.statusName" :name="item.id" />
      </el-tabs>
    </div>
    <div class="courseware-list">
      <v-table
        ref="tabs"
        :list="courseList"
        :tag="activeTab === '3' ? 'contentVideoLibrarRelease' : 'contentVideoLibrar'"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :source-arr="sourceArr"
        @handleSelectionChange="handleSelectionChange"
      >
        <el-table-column prop="transcodeStatusValue" label="转码状态">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.transcodeFailReason ? scope.row.transcodeFailReason : scope.row.transcodeStatusValue"
              placement="top-start"
            >
              <span v-if="scope.row.transcodeStatus === '4'" style="color: red;"> {{
                scope.row.transcodeStatusValue
              }}</span>
              <span v-else>{{ scope.row.transcodeStatusValue }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column v-if="!isSelect" fixed="right" label="操作" width="130">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleSee(scope.row)">查看</el-button>
            <template v-if="scope.row.transcodeStatus === '3'">
              <el-button v-if="!scope.row.isForce" type="text" size="small" @click="handleUpdate(scope.row)">
                编辑
              </el-button>
              <el-button v-if="scope.row.isForce !='SF01'" type="text" size="mini" @click="handlePublish(scope.row)">
                {{ scope.row.status === 'KCZT02' ? '发布' : '取消发布' }}
              </el-button>
              <!-- <el-button v-if="scope.row.status === 'KCZT01'" type="text" size="small" @click="handleCourse(scope.row)">创建课程</el-button>
              <el-button type="text" size="small" @click="handleExercises(scope.row)">练习题</el-button> -->
            </template>
            <el-button
              v-if="scope.row.status !== 'KCZT01' && scope.row.transcodeStatus !== '2' && scope.row.isForce !== 'SF01'"
              type="text"
              size="small"
              @click="handleDel(scope.row)"
            >删除
            </el-button>
            <el-button
              v-if="scope.row.transcodeStatus === '2'"
              type="text"
              size="small"
              @click="refresh(scope.$index, scope.row)"
            >刷新
            </el-button>
            <el-button
              v-if="scope.row.transcodeStatus === '4'"
              type="text"
              size="small"
              @click="handleAgain(scope.row)"
            >重新转码
            </el-button>
            <el-button
              v-if="scope.row.transcodeStatus !== '2' && scope.row.isForce !== 'SF01' && scope.row.subjectType !== 'KCLX04'"
              size="small"
              type="text"
              @click="handleDonwload(scope.row)"
            >
              下载</el-button>
            <el-button
              v-if="scope.row.isForce === 'SF01'"
              type="text"
              size="mini"
              @click="handleSort(scope.row)"
            >修改排序</el-button>
          </template>
        </el-table-column>
      </v-table>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
    <!--    -->
    <el-dialog
      v-if="preview.state"
      v-el-drag-dialog
      :visible.sync="preview.state"
      :close-on-click-modal="false"
      :fullscreen="isFull"
      title="预览"
      center
      width="600px"
      @close="preview.stat = false"
    >
      <span slot="title" class="my-title">
        <span>预览</span>
        <div v-if="preview.fileType === 'KCLX02'" class="full">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-full-screen"
            @click="isFull = !isFull"
          >{{ isFull ? '取消全屏' : '全屏' }}</el-button>
        </div>
      </span>
      <courseware-preview
        v-if="preview.state"
        :is-full="isFull"
        :type="preview.fileType"
        :show-type="preview.showType"
        :file-id="preview.fileId"
        style="width:100%;height:100%;"
      />
    </el-dialog>
    <create-courseware v-if="isCreate" :info="coursewareInfo" @close="closeFun" />
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :visible.sync="visibleState"
      title="查看"
      center
      width="800px"
    >
      <el-row class="see-dialog">
        <el-col :span="12">
          <div class="box">
            <div class="key">视频封面：</div>
            <div class="value">
              <el-image
                style="width: 100px; height:auto;display: inline-block;vertical-align: top;"
                :src="isOss ? coursewareInfo.subjectImgUrl : view + coursewareInfo.subjectImg"
                :preview-src-list="[isOss ? coursewareInfo.subjectImgUrl : view + coursewareInfo.subjectImg]"
              >
                <div
                  slot="error"
                  class="image-slot"
                  style="width: 100%; height: 67px;background-color: #f8f8f8;display: flex;align-items: center;justify-content: center;"
                >
                  未上传
                </div>
              </el-image>
            </div>
          </div>
        </el-col>
        <el-col v-if="coursewareInfo.subjectType != 'KCLX04'" :span="12">
          <div class="box">
            <div class="key min">视频：</div>
            <div class="value">
              <!-- 如果是转码中，只有查看-->
              <el-button
                v-if="coursewareInfo.subjectType != 'KCLX02' || coursewareInfo.transcodeStatus === '2'"
                size="small"
                type="primary"
                icon="el-icon-view"
                @click="handlePreview(coursewareInfo, 'before')"
              >
                {{ coursewareInfo.transcodeStatus === '2' ? '查看' : '原始文件' }}
              </el-button>
              <el-button
                v-if="coursewareInfo.transcodeStatus !== '2' && coursewareInfo.transcodeStatus !== '4'"
                size="small"
                type="primary"
                icon="el-icon-view"
                @click="handlePreview(coursewareInfo, 'after')"
              >{{ coursewareInfo.subjectType != 'KCLX02' ? '转码后' : '查看' }}
              </el-button>
            </div>
          </div>
        </el-col>
        <!-- 如果是课通云，不显示课件，显示课通云课程id和章节id -->
        <el-col v-if="coursewareInfo.subjectType == 'KCLX04'" :span="12">
          <div class="box">
            <div class="key">课通云课程id：</div>
            <div class="value">{{ coursewareInfo.ktyCourseId }}</div>
          </div>
          <div class="box">
            <div class="key">课通云章节id：</div>
            <div class="value">{{ coursewareInfo.ktyCourseItemId }}</div>
          </div>
          <el-button
            type="primary"
            :loading="videoLoading"
            @click="handleCheckVideo"
          >
            查看课件视频
          </el-button>
        </el-col>
        <el-col :span="24">
          <div class="box">
            <div class="key">视频名称：</div>
            <div class="value">{{ coursewareInfo.subjectName + '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">视频分类：</div>
            <div class="value">{{ coursewareInfo.subjectClassifyIdsValue || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">视频类型：</div>
            <div class="value">{{ coursewareInfo.subjectTypeValue || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">{{ coursewareInfo.subjectType != 'KCLX02' ? '视频时长' : 'PDF页数' }}：</div>
            <div class="value">{{
              fomatterTimeAndPage(coursewareInfo.subjectType, coursewareInfo.subjectDuration) || ''
            }}
            </div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">视频来源：</div>
            <div class="value">{{ coursewareInfo.subjectSource || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key max">视频转码状态：</div>
            <div class="value">{{ coursewareInfo.transcodeStatusValue }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key max">视频发布状态：</div>
            <div class="value">{{ coursewareInfo.statusValue }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">关键词：</div>
            <div class="value">{{ coursewareInfo.subjectKeyword || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">模板水印：</div>
            <div class="value">
              <el-image
                style="width: 100px; height:auto;display: inline-block;vertical-align: top;"
                :src="coursewareInfo.watermarkImgUrl"
                :preview-src-list="coursewareInfo.watermarkImgUrl"
              >
                <div
                  slot="error"
                  class="image-slot"
                  style="width: 100%; height: 67px;background-color: #f8f8f8;display: flex;align-items: center;justify-content: center;"
                >
                  未选择
                </div>
              </el-image>
            </div>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="box">
            <div class="key min">标签：</div>
            <div class="value">
              {{ coursewareInfo.subjectLabel || '' }}
            </div>
          </div>
        </el-col>
        <el-col :span="24" style="white-space: pre-line;">
          <div class="box">
            <div class="key">简介：</div>
            <div v-if="coursewareInfo.subjectIntroduce" class="value textarea-view">{{
              coursewareInfo.subjectIntroduce
            }}
            </div>
          </div>
        </el-col>
      </el-row>
      <section slot="footer" class="dialog-footer">
        <el-button style="padding: 10px 30px;" @click="visibleState = false">关 闭</el-button>
      </section>
    </el-dialog>
    <!-- 修改强制下发的排序 -->
    <el-dialog
      v-el-drag-dialog
      title="修改排序"
      width="30%"
      :visible.sync="sortDialog"
      @close="cancelDialog"
    >
      <el-input
        v-model="form.sort"
        placeholder="请输入排序值"
        type="number"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">取 消</el-button>
        <el-button type="primary" @click="handelUpdateSort">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 批量设置分类 -->
    <el-dialog
      v-el-drag-dialog
      title="设置分类"
      width="30%"
      :visible.sync="classificationDialog"
      @close="cancelClassificationDialog"
    >
      <el-cascader
        ref="classify"
        v-model="curriculumClassify"
        style="width: 100%"
        clearable
        :props="classifyProps"
        :options="classifyOptions"
      />
      <span slot="footer" class="dialog-footer">
        <el-button
          style="padding: 8px 30px"
          @click="cancelClassificationDialog"
        >取 消</el-button>
        <el-button
          style="padding: 8px 30px"
          type="primary"
          @click="handelClassification"
        >确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看课件视频 -->
    <el-dialog
      title="课件视频"
      :visible.sync="videoDialog"
      width="50%"
      center
    >
      <div class="partition">
        <video
          id="myVideo"
          class="video-js vjs-default-skin vjs-big-play-centered"
          controls
          preload="auto"
          data-setup="{}"
          style="width: 50%;height:100%;"
        >
          <source
            id="source"
            :src="videoInfo.viewUrl_origin"
            type="application/x-mpegURL"
          />
        </video>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 批量导入 -->
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :title="'课通云资源导入'"
      :visible.sync="uploadVisible"
      center
      width="550px"
    >
      <el-form style="padding-left: 22px;">
        <el-form-item label="视频分类" required>
          <el-cascader
            ref="classify"
            v-model="uploadData.subjectClassify"
            style="width:80%"
            clearable
            :props="createClassifyProps"
            :options="classifyOptions"
          />
        </el-form-item>
        <!-- <p style="color: red;text-align:left;padding: 0px;">
          {{ '根据表格中的部门名称，将人员导入到对应部门' }}
        </p> -->
      </el-form>

      <el-upload
        ref="upload"
        v-loading="loadingUpload"
        element-loading-text="正在导入请稍后"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        :auto-upload="false"
        :on-success="uploadSuccess"
        :on-error="uploadError"
        :action="uploadaction"
        :headers="uploadHeaders"
        :data="uploadData"
        accept=".xls, .xlsx"
        class="upload-model"
        drag
        multiple
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击导入</em>
        </div>
        <div slot="tip" class="el-upload__tip">
          <el-button type="text" @click="templateDownload">模版下载</el-button>
          <br>
          <br>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="uploadVisible = false">取消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="uploadSubmit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { deleteSubject, fetchList, getClassifyTree, update, get, batchPublish, batchDelet, batchSetted, getKtyVideoPath } from '../api/videoLibrary'
import { mapGetters } from 'vuex'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
import CoursewarePreview from '../components/CoursewarePreview'
import CreateCourseware from '../components/createCourseware'
import vTable from '@/components/Table'
import videojs from 'video.js'
import 'videojs-contrib-hls'
import { getToken } from '@/utils/auth'
import { exportSign, importSign } from '@/utils/fileImportOrExportSign'
export default {
  name: 'VideoLibrary',
  components: { Pagination, CoursewarePreview, CreateCourseware, vTable },
  directives: { elDragDialog },
  props: {
    isSelect: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      classificationDialog: false,
      multipleSelection: [],
      curriculumClassify: [],
      subjectClassify: '',
      isFull: false, // 是否全屏
      listLoading: false,
      list: null,
      total: 0,
      searchshow: true,
      uploadVisible: false,
      search: {
        subjectName: '',
        subjectClassify: '',
        subjectKeyword: '',
        subjectSource: '',
        subjectType: 'KCLX01,KCLX04' // 固定课程类型为视频
      },
      classifyProps: {
        label: 'classifyName',
        value: 'id',
        checkStrictly: true
      },
      createClassifyProps: {
        label: 'classifyName',
        value: 'id',
        checkStrictly: true
      },
      classifyOptions: [],
      statusOptions: [
        {
          statusName: '全部',
          id: '1'
        },
        {
          statusName: '转码成功/未发布',
          id: '2'
        },
        {
          statusName: '已发布',
          id: '3'
        },
        {
          statusName: '转码中',
          id: '4'
        },
        {
          statusName: '转码失败',
          id: '5'
        }
      ],
      activeTab: '1',
      listQuery: {
        page: 1,
        limit: 10,
        subjectName: ''
      },
      checkList: [],
      courseList: [],
      view: '/API-DOCUMENT/document/file/download?id=',
      dict: {
        KCLX: [] // 视频类型
      },
      preview: {
        fileId: '',
        fileType: '',
        showType: '',
        state: false
      },
      coursewareInfo: {},
      visibleState: false,
      isCreate: false,
      isOss: sessionStorage.getItem('FILE_SAVE_THIRD_CONFIG') || false,
      sourceArr: ['subjectImgUrl'],
      isCreatePage: true,
      form: {
        id: '',
        sort: ''
      },
      sortDialog: false,
      videoLoading: false,
      videoDialog: false,
      videoInfo: {},
      myVideo: null,
      uploadaction: '',
      uploadData: {
        subjectClassify: []
      },
      loadingUpload: false,
      uploadHeaders: {
        'ttsxyhcs': getToken(),
        'ttsxbid': 1
      }
    }
  },
  computed: {
    ...mapGetters(['sidebar'])
  },
  created() {
    this.activeTab = this.$route.query.active || '1'
    this.getClassifyOption()
    this.getList()
  },
  // activated() {
  //   if (this.isCreatePage) { this.listQuery.page = 1 }
  //   this.getList()
  // },
  methods: {
    handleDonwload(item) {
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = '/API-DOCUMENT/document/file/download?id=' + item.courseId

      link.setAttribute('download', item.subjectName)
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    /**
     *多选
     */
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    handleClose() {
      this.videoDialog = false
      this.myVideo.pause()
    },
    // 关闭设置分类弹框
    cancelClassificationDialog() {
      this.classificationDialog = false
      this.curriculumClassify = []
    },
    // 查看该课件视频
    handleCheckVideo() {
      this.videoLoading = true
      return new Promise((resolve, reject) => {
        getKtyVideoPath({ courseId: this.coursewareInfo.courseId }).then(
          (res) => {
            this.videoDialog = true
            this.videoLoading = false
            this.videoInfo = res.data.data
            this.getVideo()
          }
        ).catch(() => {
          this.videoLoading = false
        })
      })
    },
    getVideo() {
      setTimeout(() => {
        // videojs 简单使用
        this.myVideo = videojs('myVideo', {
          bigPlayButton: true,
          textTrackDisplay: false,
          posterImage: false,
          errorDisplay: false
        })
        this.myVideo.play()
      }, 300)
    },
    // 提交设置的课程分类
    handelClassification() {
      if (this.multipleSelection.length > 0) {
        const loading = this.$loading({
          lock: true,
          text: '请稍后',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.3)'
        })
        const params = {
          id: this.multipleSelection.map(item => {
            return item.id
          }).join(','),
          subjectClassify: this.curriculumClassify[this.curriculumClassify.length - 1]
        }
        batchSetted(params).then(res => {
          loading.close()
          console.log(res, 935)
          if (res.data.code === '200') {
            this.$message({
              message: '修改成功',
              type: 'success'
            })
            this.cancelClassificationDialog()
            this.getList()
            this.$refs.tabs.handleChangeSelection(this.multipleSelection)
          }
        }).catch(() => {
          loading.close()
        })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择需要修改的视频'
        })
      }
    },
    handleSelectPlatform() {
      this.$router.push({
        path: '/contentRepository/videoLibrary/SelectCourse4platform',
        query: {}
      })
    },
    refresh(index, row) {
      this.getData(row.id).then((res) => {
        if (res !== 0) {
          this.$set(this.courseList, index, res)
        }
      })
    },
    getData(id) {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        get({ id: id })
          .then((res) => {
            loading.close()
            resolve(res.data.data)
          })
          .catch((e) => {
            loading.close()
            resolve(0)
          })
      })
    },
    /**
     * 格式化视频时长单位
     */
    fomatterTimeAndPage(type, t) {
      if (type === 'KCLX02') {
        return t + '页'
      } else {
        const fTime = t || 0
        let time = parseInt(fTime) + '秒'
        if (parseInt(fTime) > 60) {
          var second = parseInt(fTime) % 60
          var min = parseInt(fTime / 60)
          time = min + '分' + second + '秒'

          if (min > 60) {
            min = parseInt(fTime / 60) % 60
            var hour = parseInt(parseInt(fTime / 60) / 60)
            time = hour + '小时' + min + '分' + second + '秒'

            if (hour > 24) {
              hour = parseInt(parseInt(fTime / 60) / 60) % 24
              var day = parseInt(parseInt(parseInt(fTime / 60) / 60) / 24)
              time = day + '天' + hour + '小时' + min + '分' + second + '秒'
            }
          }
        }
        return time
      }
    },
    /**
     * 转换成数组
     */
    getArr(str) {
      try {
        return str.split(',')
      } catch (e) {
        return []
      }
    },
    /**
     * 创建课程
     */
    handleCourse(item) {
      this.isCreatePage = false
      this.$router.push({
        path: this.$filterPath('create'),
        query: { i: item.id, t: 'courseware', active: this.activeTab }
      })
    },
    closeFun(type) {
      this.isCreate = false
      if (type !== 0) {
        this.getList()
      }
    },
    /**
     * 选项卡切换
     */
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      this.getList()
    },
    // handleSelectionChange(val) {
    //   this.multipleSelection = val
    //   this.$emit('handleSelect', this.multipleSelection)
    // },
    /**
     * 预览
     * i: 视频信息
     */
    handlePreview(i, t) {
      this.preview.fileId = t === 'before' ? i.courseId : i.courseIdUrl
      this.preview.fileType = i.subjectType
      this.preview.showType = t
      this.preview.state = true
    },
    /**
     * 查看
     * i: 视频信息
     */
    handleSee(i) {
      this.coursewareInfo = i
      this.visibleState = true
    },
    /**
     * 重新转码
     * i: 视频信息
     */
    handleAgain(i) {
      this.coursewareInfo = i
      this.isCreate = true
    },
    /**
     * 练习题
     */
    handleExercises(item) {
      this.$router.push({ path: this.$filterPath('exercises'), query: { ci: item.id, active: this.activeTab }})
    },
    /**
     * 启用/禁用
     */
    handlePublish(row) {
      const state = row.status === 'KCZT01' ? 'KCZT02' : 'KCZT01'
      let msg = ''
      if (row.status === 'KCZT01') {
        msg = '取消发布'
      } else {
        msg = '发布'
      }
      this.$confirm('确定' + msg + '该视频吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            update({ id: row.id, status: state })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {
        })
    },
    /**
     * 获取视频分类
     */
    getClassifyOption() {
      return new Promise((resolve, reject) => {
        getClassifyTree({ classifyType: 'JNZQFL05' })
          .then(({ data }) => {
            this.classifyOptions = data.data || []
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        type: this.isSelect ? '3' : this.activeTab
      }
      if (this.searchshow) {
        query['subjectName'] = this.listQuery.subjectName
        query['subjectType'] = this.search.subjectType
      } else {
        query['subjectName'] = this.search.subjectName
        query['subjectClassify'] = this.search.subjectClassify.length > 0 ? this.search.subjectClassify[this.search.subjectClassify.length - 1] : ''
        query['subjectKeyword'] = this.search.subjectKeyword
        query['subjectSource'] = this.search.subjectSource
        query['subjectType'] = this.search.subjectType
      }
      return new Promise((resolve, reject) => {
        fetchList(query)
          .then((response) => {
            this.courseList = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            this.listLoading = false
            reject(error)
          })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.subjectName = ''
      for (const i in this.search) {
        this.search['' + i + ''] = ''
      }
      this.listQuery.page = 1
      this.getList()
    },
    handleUpdate(item) {
      this.isCreatePage = false
      this.$router.push({
        path: this.$filterPath('videoLibraryManage'),
        query: { i: item.id, type: 'u', active: this.activeTab }
      })
    },
    handleDeletes() {
      const arr = []
      if (this.checkList.length > 0) {
        this.checkList.forEach((item) => {
          arr.push(item)
        })
        var ids = arr.join(',')
        this.deleteSubject(ids)
      } else {
        this.$message({
          message: '请选择需要删除的数据！',
          type: 'error'
        })
      }
    },
    handleDel(row) {
      if (row.status === 'KCZT01') {
        this.$message({
          message: '视频已发布，无法删除',
          type: 'warning'
        })
      } else {
        this.deleteSubject(row.id)
      }
    },
    deleteSubject(ids) {
      this.$confirm('此操作将永久删除该视频, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            deleteSubject({ id: ids })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '删除成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    filtercolumn(scope, item) {
      if (item === 'subjectType') {
        return scope.row[item] === 'KCLX04' ? '课通云' : '本系统'
      } else {
        return scope.row[item] ? scope.row[item] : ''
      }
    },
    handleSelectDelet() {
      if (this.multipleSelection.length > 0) {
        this.$confirm('此操作将永久删除选中视频, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            const loading = this.$loading({
              lock: true,
              text: '请稍后',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.3)'
            })
            const params = {
              ids: this.multipleSelection.map((i) => i.id).join(',')
            }
            batchDelet(params)
              .then((res) => {
                loading.close()
                this.getList()
              })
              .catch((err) => loading.close(err))
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择需要删除的视频'
        })
      }
    },
    handleSelectSend() {
      if (this.multipleSelection.length > 0) {
        const loading = this.$loading({
          lock: true,
          text: '请稍后',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.3)'
        })
        const params = {
          id: this.multipleSelection.map((i) => i.id).join(','),
          status: 'KCZT01'
        }
        batchPublish(params)
          .then((res) => {
            loading.close()
            this.getList()
          })
          .catch((err) => loading.close(err))
      } else {
        this.$message({
          type: 'warning',
          message: '请选择需要发布的视频'
        })
      }
    },
    handleUpload() {
      this.uploadaction = '/API-ENTERPRISE-BACKEND/backend/subject/importKtySubject'
      this.uploadVisible = true
      this.$nextTick(() => {
        this.$refs.upload.clearFiles()
      })
    },
    uploadSuccess(data) {
      this.loadingUpload = false
      if (data.code === '200') {
        this.getList()
        this.uploadVisible = false
      } else {
        this.$message.error(data.msg || '批量导入失败')
        this.$refs.upload.clearFiles()
        this.getList()
        if (data.data && data.data.fileid) {
          setTimeout(() => {
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = '/API-ENTERPRISE-BACKEND/backend/subject/downloadCheckFile' + exportSign({ errorId: data.data.fileid }).paramStr
            link.setAttribute('download', '错误信息.xls')
            link.setAttribute('target', '_blank')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
          }, 1000)
        }
      }
    },
    uploadError(err) {
      this.loadingUpload = false
      this.$message.error(err || '网络异常')
      this.$refs.upload.clearFiles()
    },
    uploadSubmit() {
      if (this.uploadData.subjectClassify.length === 0) {
        this.$message({
          message: '请选择视频类型',
          type: 'warning'
        })
        return
      }
      this.uploadData.subjectClassify = this.uploadData.subjectClassify[this.uploadData.subjectClassify.length - 1]
      this.$set(this, 'uploadHeaders', importSign(this.uploadHeaders, this.uploadData))
      this.$refs.upload.submit()
      this.loadingUpload = true
    },
    templateDownload() {
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = '/API-ENTERPRISE-BACKEND/backend/subject/downloadTemplate'
      link.setAttribute('download', '模版.xls')
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    // 修改排序
    handelUpdateSort() {
      if (this.form.sort === '') {
        this.$message({
          message: '请输入排序值',
          type: 'warning'
        })
        return
      }
      const obj = Object.assign({}, this.form)
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      update(obj).then(res => {
        if (res.data.code === '200') {
          loading.close()
          this.sortDialog = false
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.getList()
        } else {
          loading.close()
          this.$message({
            message: '修改失败',
            type: 'error'
          })
        }
      }).catch(() => {
        loading.close()
      })
    },
    // 强制下发数组修改排序
    handleSort(row) {
      this.form.id = row.id
      this.sortDialog = true
    },
    // 取消修改排序
    cancelDialog() {
      this.sortDialog = false
      for (const k in this.form) {
        this.form[k] = ''
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
$dark_gray: #bfced6;
.courseware-container {
  padding: 20px;

  .el-button + .el-button {
    margin-left: 0 !important;
  }

  .my-title {
    width: 100%;
    display: inline-block;
    font-size: 16px !important;
    font-family: PingFangSC-Medium !important;
    font-weight: 700 !important;
    color: #333333 !important;
    position: relative;

    .full {
      position: absolute;
      width: 100px;
      height: 58px;
      right: 50px;
      top: -18px;
      display: flex;
      align-items: center;
      text-align: right;
    }
  }

  .courseware-search {
    background-color: #fff;
    padding: 0 20px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 20px;
      }
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .courseware-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .courseware-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .courseware-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .courseware-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;

    .el-tabs__nav-wrap::after {
      display: none;
    }

    .el-tabs__header {
      margin: 0;
    }
  }

  .courseware-btn {
    display: flex;
    height: 46px;
    line-height: 46px;
    width: 100%;

    .btn-title {
      flex: 1;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .courseware-list {
    background-color: white;
    margin-top: 10px;
    padding: 10px;

    .el-image {
      width: 100%;
      height: auto;
      max-height: 140px;

      .image-slot {
        width: 100%;
        height: 67px;
        background-color: #f8f8f8;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    .el-form-item {
      margin-bottom: 5px;
    }

    .el-dropdown-link {
      cursor: pointer;
      @include font-color($mainColor);
    }
  }

  .pagination-container {
    background: none;
  }

  .el-row.see-dialog {
    height: 500px;
    overflow-y: auto;
    padding: 5px 40px;

    .box {
      display: flex;
      width: 100%;
      min-height: 38px;
      .key {
        width: 110px;
        &.max {
          width: 100px;
        }
        &.min {
          width: 50px;
        }
      }
      .value {
        flex: 1;
        color: #333;
        font-weight: 500;
        padding-right: 30px;

        &.textarea-view {
          white-space: pre-line;
          border: 1px solid #e5e5e5;
          border-radius: 6px;
          padding: 10px;
          color: #333;
          background-color: #f9f9f9;
          font-weight: normal;
        }
      }
    }

    .el-col {
      padding-top: 10px;
      margin-top: 15px;
    }
  }

  .cell {
    .el-image {
      width: 100%;
    }
  }
	.partition {
    position: relative;
    height: 200px;
		#myVideo {
			height: 100% !important;
			margin: 10vh auto;
		}
	}
  .upload-model {
    text-align: center;
  }
  .image-preview .el-dialog__body {
    text-align: center;
    .image-box {
      width: 200px;
      height: 80px;
      border: 2px dashed #ff9f91;
      border-radius: 5px;
    }
  }
}
</style>
